package com.zhudoo.zhilian.util.service;

import com.zhudoo.zhilian.dao.entity.Tip;
import com.zhudoo.zhilian.dao.entity.User;
import com.zhudoo.zhilian.service.TipService;
import com.zhudoo.zhilian.service.UserService;
import com.zhudoo.zhilian.util.StringUtils;

import java.util.HashMap;
import java.util.Map;


public class TipUtil {

    public static Map splitPrice(String price) {
        Map<String, Integer> resultMap = new HashMap<>(2);
        if (StringUtils.isNotEmpty(price)) {
            String[] strings = price.split("~");
            if (strings.length == 2) {
                resultMap.put("startPrice", Integer.parseInt(strings[0]));
                resultMap.put("endPrice", Integer.parseInt(strings[1]));
                return resultMap;
            } else {
                resultMap.put("startPrice", null);
                resultMap.put("endPrice", null);
            }
        }
        resultMap.put("startPrice", null);
        resultMap.put("endPrice", null);
        return resultMap;
    }

    public static String getOnlyStr(Integer userId, Integer tipType, Integer stationId, Integer hall, Integer roomType, Integer budget, String checkInDate) {
        String str = userId + "-" + tipType + "-" + stationId + "-" + hall + "-" + roomType + "-" + budget + "-" + checkInDate;
        return str;
    }

    public static String getTitle(Integer tipType, String lineName, String stationName) {
        String str = TipService.TYPE_NAME_MAP.get(tipType) + "·" + lineName + stationName;
        return str;
    }


    public static boolean getShowContact(User user, Tip tip) {
        //转租和找室友
        if (tip.getType() == TipService.TIP_TYPE_2 || tip.getType() == TipService.TIP_TYPE_3) {
            return user.getType() == UserService.TYPE_1;
        }
        return true;
    }

    public static boolean getShowAppointment(User user, Tip tip) {
        //是否显示约看
        if (user.getType() == UserService.TYPE_2 || user.getType() == UserService.TYPE_3) {
            return tip.getType() != TipService.TIP_TYPE_1 || tip.getUserId() != user.getId().intValue();
        } else {
            return false;
        }
    }


    public static boolean getAllowEdit(Long countByTipId, Tip tip) {
        return countByTipId == 0 && tip.getStatus() == TipService.TIP_STATUS_1;
    }
}
